import java.util.Arrays;
import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/4/3 21:05
 */

public class Solution {
    public void sortColors(int[] nums) {
        int left = -1, right = nums.length, i = 0;

        while (i < right) {
            if (nums[i] == 0) swap(nums, ++left, i++);
            else if (nums[i] == 1) i++;
            else if (nums[i] == 2) swap(nums, --right, i);
        }
    }

    private void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int len = in.nextInt();
            int[] nums = new int[len];
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
            }
            Solution solution = new Solution();
            solution.sortColors(nums);
            System.out.println(Arrays.toString(nums));
        }
    }
}